/**************************提示：只允许修改开发区域，其他区域会被覆盖！********************************/
mod.definePage("extend/re/contract/js/ReWorkLoadConfirmBillEditPage_eascard001",function(waf){
    //@beginUseModule
    var ReContractEditPageUtil = mod.useSync("re/contract/common/js/ReContractEditPageUtil");
    var ReWorkLoadConfirmBillEditPage = mod.useSync("re/contract/js/ReWorkLoadConfirmBillEditPage");
    //@endUseModule
    var _public = {},_private = {},me=_self;
    var isProject = false;//当前合同是否工程项
    var isAloneTax = "1";//是否单税率
    //@beginPublic
    waf.extend(_public,{
        //控件事件描述:
        contractDataOnChange:function(event,value){
            return _private.contractDataOnChange(event,value);
        }
        ,
        //控件事件描述:
        editgridAfterSaveCell:function(rowid,cellname,value,iRow,Col,oldValue){
            return _private.editgridAfterSaveCell(rowid,cellname,value,iRow,Col,oldValue);
        }
        ,
        //控件事件描述:
        editGridBeforeEdit:function(rowid,cellname,value,iRow,iCol,rowdata){
            return _private.editGridBeforeEdit(rowid,cellname,value,iRow,iCol,rowdata);
        }
        ,
        //页面事件描述:页面打开事件
        afterPageOnload:function(e){
            return _private.afterPageOnload(e);
        }
        ,
        //页面事件描述:extSaveOverWrite
        extSaveOverWrite:function(e){
            return _private.extSaveOverWrite(e);
        }
        ,
        //页面事件描述:extSaveBefore
        extSaveBefore:function(e){
            return _private.extSaveBefore(e);
        }
        ,
        //页面事件描述:beforeSave
        beforeSave:function(e){
            return _private.beforeSave(e);
        }
        ,
        //页面事件描述:submitBeforeBizCheckNew
        submitBeforeBizCheckNew:function(e){
            return _private.submitBeforeBizCheckNew(e);
        }
    });
    _self.subscribeEvent("pageOnLoadEvent",_public.afterPageOnload,"after");
    _self.subscribeEvent("extSaveActionEvent",_public.extSaveOverWrite,"overwrite");
    _self.subscribeEvent("extSaveActionEvent",_public.extSaveBefore,"before");
    _self.subscribeEvent("saveActionEvent",_public.beforeSave,"before");
    _self.subscribeEvent("submitBeforeBizCheckActionEvent",_public.submitBeforeBizCheckNew,"before");
    //@endPublic
    //@beginTemplateFunctions

    //@endTemplateFunctions

    /**************************开发区域开始**********************************************/
    //@beginPrivate
    waf.extend(_private,{
        contractDataOnChange:function(event,value){

            ReWorkLoadConfirmBillEditPage.contractDataOnChange(event,value);

            waf("#ext_editgrid").wafGrid("clearGridData",true);
            var contractValue = waf("#contract").wafPromptBox("getValue");
            if(contractValue){
                var projectData = _private.doControllerMethod("/fdc/finance/web/ReWorkLoadConfirmBill.do?method=loadDetailsEntry",{contractId:contractValue.id});
                if(projectData){
                    for(var i =0;i<projectData.length;i++){
                        var newRow = {
                            projectNumber:projectData[i].projectNumber,
                            projectName:projectData[i].projectName,
                            jzsqmljjsAmt:projectData[i].jzsqmljjsAmt,
                            jzbqmljjsAmt:projectData[i].jzbqmljjsAmt
                        };
                        waf("#ext_editgrid").wafGrid('addRow',{data:newRow,autoFocus:false});


                    }



                    _private.editGridLockCell(contractValue.id);



                }else{
                    _self.showError("合同查找产值确认单有误！");
                }
            }else{
                _self.showError("当前选中合同为空，请重新选择！");
            }
        },


        editGridLockCell:function(contractId){
            waf("#ext_editgrid").wafGrid("setColumnStyle","projectName","background-color:#EFF3F6",true);
            waf("#ext_editgrid").wafGrid("setColumnStyle","jzsqmljjsAmt","background-color:#EFF3F6;text-align:right",true);
            waf("#ext_editgrid").wafGrid("setColumnStyle","currentSetAmt","background-color:#EFF3F6;text-align:right",true);
            waf("#ext_editgrid").wafGrid("setColumnStyle","jzbqmljjsAmt","background-color:#EFF3F6;text-align:right",true);


            isAloneTax = _private.doControllerMethod("/fdc/finance/web/ReWorkLoadConfirmBill.do?method=selectContentEntry",{contractId:contractId});
            var rowId = "";

            var editGridCount = waf("#ext_editgrid").wafGrid("getRowCount");
            if(editGridCount==9){//因为分录是固定的，直接用分录行数判断是否是工程项
                rowId = waf("#ext_editgrid").wafGrid("getRowId",8);

                //行融合
                if(isAloneTax!="1"){//多税率
                    _private.contraryMergeTableByIndex("ext_editgrid",7,3,7,8);
                    var rowId7 = waf("#ext_editgrid").wafGrid("getRowId",7);
                    var oldRemark7 = waf("#ext_editgrid").wafGrid('getCell',rowId7,"remark")
                    if(!oldRemark7 || oldRemark7.length==0){
                        waf("#ext_editgrid").wafGrid('setCell',rowId7,"remark","存在多税率,请在此录入!");
                    }

                    waf("#ext_editgrid").wafGrid("setCellStyle",rowId7,"remark","text-align:center");

                }else{//单税率
                    _private.mergeTableByIndex("ext_editgrid",7,3,7,7);
                    var rowId7 = waf("#ext_editgrid").wafGrid("getRowId",7);
                    waf("#ext_editgrid").wafGrid("setCellStyle",rowId7,"jzsqmljjsAmt","background-color:#EFF3F6;text-align:center");
                }

                isProject = true;

                //锁定 不含税结算金额合计
                rowId6 = waf("#ext_editgrid").wafGrid("getRowId",6);
                var ret1 = jQuery('#ext_editgrid').wafGrid('lockCell', rowId6, "currentReqAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId6,"currentReqAmt","background-color:#EFF3F6;text-align:right");

                var ret2 = jQuery('#ext_editgrid').wafGrid('lockCell', rowId6, "currentReqSubAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId6,"currentReqSubAmt","background-color:#EFF3F6;text-align:right");

                //锁定  含税结算金额合计
                rowId9 = waf("#ext_editgrid").wafGrid("getRowId",9);
                var ret3 = jQuery('#ext_editgrid').wafGrid('lockCell', rowId9, "currentReqAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId9,"currentReqAmt","background-color:#EFF3F6;text-align:right");
                var ret4 = jQuery('#ext_editgrid').wafGrid('lockCell', rowId9, "currentReqSubAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId9,"currentReqSubAmt","background-color:#EFF3F6;text-align:right");

                var ret1 = jQuery('#ext_editgrid').wafGrid('unLockCell', rowId7, "jzsqmljjsAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId7,"jzsqmljjsAmt","background-color:white;text-align:center");
            }else{
                rowId = waf("#ext_editgrid").wafGrid("getRowId",5);

                //行融合
                if(isAloneTax!="1"){//多税率
                    _private.contraryMergeTableByIndex("ext_editgrid",4,3,4,8);
                    var rowId4 = waf("#ext_editgrid").wafGrid("getRowId",4);

                    var oldRemark4 = waf("#ext_editgrid").wafGrid('getCell',rowId4,"remark")
                    if(!oldRemark4 || oldRemark4.length==0){
                        waf("#ext_editgrid").wafGrid('setCell',rowId4,"remark","存在多税率,请在此录入!");
                    }

                    waf("#ext_editgrid").wafGrid("setCellStyle",rowId4,"remark","text-align:center");
                }else{//单税率
                    _private.mergeTableByIndex("ext_editgrid",4,3,4,7);
                    var rowId4 = waf("#ext_editgrid").wafGrid("getRowId",4);
                    waf("#ext_editgrid").wafGrid("setCellStyle",rowId4,"jzsqmljjsAmt","text-align:center;background-color:#EFF3F6");

                }

                isProject = false;

                //锁定 不含税结算金额合计
                rowId3 = waf("#ext_editgrid").wafGrid("getRowId",3);
                var ret1 = jQuery('#ext_editgrid').wafGrid('lockCell', rowId3, "currentReqAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId3,"currentReqAmt","background-color:#EFF3F6;text-align:right");
                var ret2 = jQuery('#ext_editgrid').wafGrid('lockCell', rowId3, "currentReqSubAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId3,"currentReqSubAmt","background-color:#EFF3F6;text-align:right");
                //锁定  含税结算金额合计
                rowId6 = waf("#ext_editgrid").wafGrid("getRowId",6);
                var ret3 = jQuery('#ext_editgrid').wafGrid('lockCell', rowId6, "currentReqAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId6,"currentReqAmt","background-color:#EFF3F6;text-align:right");
                var ret4 = jQuery('#ext_editgrid').wafGrid('lockCell', rowId6, "currentReqSubAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId6,"currentReqSubAmt","background-color:#EFF3F6;text-align:right");

                var ret1 = jQuery('#ext_editgrid').wafGrid('unLockCell', rowId4, "jzsqmljjsAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId4,"jzsqmljjsAmt","background-color:white;text-align:center");

            }

            //if(isAloneTax!="1"){//多税率
            var ret1 = jQuery('#ext_editgrid').wafGrid('unLockCell', rowId, "currentReqAmt");
            waf("#ext_editgrid").wafGrid("setCellStyle",rowId,"currentReqAmt","background-color:white;text-align:right");
            var ret2 = jQuery('#ext_editgrid').wafGrid('unLockCell', rowId, "currentReqSubAmt");
            waf("#ext_editgrid").wafGrid("setCellStyle",rowId,"currentReqSubAmt","background-color:white;text-align:right");
            var ret3 = jQuery('#ext_editgrid').wafGrid('lockCell', rowId, "currentSetAmt");
            waf("#ext_editgrid").wafGrid("setCellStyle",rowId,"currentSetAmt","background-color:#EFF3F6;text-align:right");
            /*}else{//单税率
                var ret1 = jQuery('#ext_editgrid').wafGrid('lockCell', rowId, "currentReqAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId,"currentReqAmt","background-color:#EFF3F6;text-align:right");
                var ret2 = jQuery('#ext_editgrid').wafGrid('lockCell', rowId, "currentReqSubAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId,"currentReqSubAmt","background-color:#EFF3F6;text-align:right");
                var ret3 = jQuery('#ext_editgrid').wafGrid('lockCell', rowId, "currentSetAmt");
                waf("#ext_editgrid").wafGrid("setCellStyle",rowId,"currentSetAmt","background-color:#EFF3F6;text-align:right");
            }*/

            //设置列头
            if(isProject){
                $("#ext_editgrid").wafGrid('setLabel','currentSetAmt','本期结算');
            }else{
                $("#ext_editgrid").wafGrid('setLabel','currentSetAmt','本期结算/应付金额');
            }


        },


        afterPageOnload:function(e){
            var contractValue = waf("#contract").wafPromptBox("getValue");
            if(_self.operatState == "ADDNEW" && waf("#ext_editgrid").wafGrid("getRowCount")==0 && contractValue !=null){
                waf("#ext_editgrid").wafGrid("clearGridData",true);
                var contractValue = waf("#contract").wafPromptBox("getValue");
                if(contractValue){
                    var projectData = _private.doControllerMethod("/fdc/finance/web/ReWorkLoadConfirmBill.do?method=loadDetailsEntry",{contractId:contractValue.id});
                    if(projectData){
                        for(var i =0;i<projectData.length;i++){
                            var newRow = {
                                projectNumber:projectData[i].projectNumber,
                                projectName:projectData[i].projectName,
                                jzsqmljjsAmt:projectData[i].jzsqmljjsAmt,
                                jzbqmljjsAmt:projectData[i].jzbqmljjsAmt
                            };
                            waf("#ext_editgrid").wafGrid('addRow',{data:newRow,autoFocus:false});


                        }



                        _private.editGridLockCell(contractValue.id);



                    }else{
                        _self.showError("合同查找产值确认单有误！");
                    }
                }else{
                    _self.showError("当前选中合同为空，请重新选择！");
                }
            }



            var contractValue = waf("#contract").wafPromptBox("getValue");
            if(contractValue){
                _private.editGridLockCell(contractValue.id);
            }

            //因为标准功能，直接在网页无法隐藏
            //$("#toolBar_save").hide();
        },



        doControllerMethod:function(paramUrl,paramData){
            var returnValue = null;
            waf.doPost({
                url: waf.getContextPath() + paramUrl,
                data: paramData,
                async:false,
                success: function(data) {
                    returnValue = data;
                },
                error: function(errorInfo,errorDetail) {
                    if(errorInfo)
                    {
                        if(errorDetail.indexOf("10-fdc_waf<br/>")>0)
                        {
                            _self.showError(errorInfo);
                        }
                        else
                        {
                            _self.showError(errorInfo,errorDetail);
                        }
                    }
                    else
                    {
                        _self.showError(errorInfo);
                    }
                }
            });

            return returnValue;
        },

        editgridAfterSaveCell:function(rowid,cellname,value,iRow,Col,oldValue){
            if(cellname == "remark"){//备注字段修改不需代码处理

                return;
            }


            //计税金改成可以手动修改的模式
            if(isAloneTax=="1"&&cellname=="currentReqAmt"||cellname=="currentReqSubAmt"){
                var rowId8 = waf("#ext_editgrid").wafGrid("getRowId",8);
                var rowId5 = waf("#ext_editgrid").wafGrid("getRowId",5);
                if(isProject&&rowId8==rowid){
                    var currentReqAmt=waf("#ext_editgrid").wafGrid('getCell',rowId8,"currentReqAmt");
                    var currentReqSubAmt=waf("#ext_editgrid").wafGrid('getCell',rowId8,"currentReqSubAmt");
                    waf("#ext_editgrid").wafGrid('setCell',rowId8,"currentSetAmt",_private.subtract(currentReqAmt,currentReqSubAmt));//计算本期结算
                    //计算含税金额合计
                    var rowId9 = waf("#ext_editgrid").wafGrid("getRowId",9);
                    var count=waf("#ext_editgrid").wafGrid('getCell',rowId9,cellname);
                    var amount=_private.add(_private.subtract(count,oldValue),value);
                    waf("#ext_editgrid").wafGrid('setCell',rowId9,cellname,amount);

                    var currentReqAmtCount=waf("#ext_editgrid").wafGrid('getCell',rowId9,"currentReqAmt");
                    var currentReqSubAmtCount=waf("#ext_editgrid").wafGrid('getCell',rowId9,"currentReqSubAmt");
                    waf("#ext_editgrid").wafGrid('setCell',rowId9,"currentSetAmt",_private.subtract(currentReqAmtCount,currentReqSubAmtCount));//计算合计
                    waf("#workLoadOriAmt").wafNumberField("setValue",_private.subtract(currentReqAmtCount,currentReqSubAmtCount));
                    //waf("#originalAmount").wafNumberField("setValue",amount);
                    return;
                }else if(!isProject&&rowId5==rowid){
                    var currentReqAmt=waf("#ext_editgrid").wafGrid('getCell',rowId5,"currentReqAmt");
                    var currentReqSubAmt=waf("#ext_editgrid").wafGrid('getCell',rowId5,"currentReqSubAmt");
                    waf("#ext_editgrid").wafGrid('setCell',rowId5,"currentSetAmt",_private.subtract(currentReqAmt,currentReqSubAmt));//计算本期结算
                    //计算含税金额合计
                    var rowId6 = waf("#ext_editgrid").wafGrid("getRowId",6);
                    var count=waf("#ext_editgrid").wafGrid('getCell',rowId6,cellname);
                    var amount=_private.add(_private.subtract(count,oldValue),value);
                    waf("#ext_editgrid").wafGrid('setCell',rowId6,cellname,amount);

                    var currentReqAmtCount=waf("#ext_editgrid").wafGrid('getCell',rowId6,"currentReqAmt");
                    var currentReqSubAmtCount=waf("#ext_editgrid").wafGrid('getCell',rowId6,"currentReqSubAmt");
                    waf("#ext_editgrid").wafGrid('setCell',rowId6,"currentSetAmt",_private.subtract(currentReqAmtCount,currentReqSubAmtCount));//计算合计
                    waf("#workLoadOriAmt").wafNumberField("setValue",_private.subtract(currentReqAmtCount,currentReqSubAmtCount));
                    //waf("#originalAmount").wafNumberField("setValue",amount);
                    return;
                }
            }

            var currentReqAmt = waf("#ext_editgrid").wafGrid('getCell',rowid,"currentReqAmt");
            if(!currentReqAmt || currentReqAmt.length==0){
                currentReqAmt = 0.00;
            }
            var currentSubAmt = waf("#ext_editgrid").wafGrid('getCell',rowid,"currentReqSubAmt");
            if(!currentSubAmt || currentSubAmt.length==0){
                currentSubAmt = 0.00;
            }


            var currentSetAmt = _private.subtract(currentReqAmt,currentSubAmt,2);
            if(!currentSetAmt || currentSetAmt.length==0){
                currentSetAmt = 0.00;
            }
            waf("#ext_editgrid").wafGrid('setCell',rowid,"currentSetAmt",currentSetAmt);
            //截至上期末累计结算金额
            var sqAmt = waf("#ext_editgrid").wafGrid('getCell',rowid,"jzsqmljjsAmt");
            if(!sqAmt || sqAmt.length==0){
                sqAmt = 0.00;
            }
            //计算出截至本期末累计结算金额
            var bqAmt = _private.add(sqAmt,currentSetAmt,2);
            waf("#ext_editgrid").wafGrid('setCell',rowid,"jzbqmljjsAmt",bqAmt);


            if(isProject){//工程项
                var rowId1 = waf("#ext_editgrid").wafGrid("getRowId",1);
                var rowId2 = waf("#ext_editgrid").wafGrid("getRowId",2);
                var rowId3 = waf("#ext_editgrid").wafGrid("getRowId",3);
                var rowId4 = waf("#ext_editgrid").wafGrid("getRowId",4);
                var rowId5 = waf("#ext_editgrid").wafGrid("getRowId",5);
                var rowId6 = waf("#ext_editgrid").wafGrid("getRowId",6);
                var rowId7 = waf("#ext_editgrid").wafGrid("getRowId",7);
                var rowId8 = waf("#ext_editgrid").wafGrid("getRowId",8);
                var rowId9 = waf("#ext_editgrid").wafGrid("getRowId",9);

                //*******************************合计不含税*******************************
                //本期申请金额
                var row1CurReqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId1,"currentReqAmt");
                var row2CurReqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId2,"currentReqAmt");
                var row3CurReqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId3,"currentReqAmt");
                var row4CurReqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId4,"currentReqAmt");
                var row5CurReqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId5,"currentReqAmt");

                var row6CurReqAmt = _private.addFiveNumber(row1CurReqAmt,row2CurReqAmt,row3CurReqAmt,row4CurReqAmt,row5CurReqAmt,2);
                waf("#ext_editgrid").wafGrid('setCell',rowId6,"currentReqAmt",row6CurReqAmt);
                //本期审减金额
                var row1CurSubAmt = waf("#ext_editgrid").wafGrid('getCell',rowId1,"currentReqSubAmt");
                var row2CurSubAmt = waf("#ext_editgrid").wafGrid('getCell',rowId2,"currentReqSubAmt");
                var row3CurSubAmt = waf("#ext_editgrid").wafGrid('getCell',rowId3,"currentReqSubAmt");
                var row4CurSubAmt = waf("#ext_editgrid").wafGrid('getCell',rowId4,"currentReqSubAmt");
                var row5CurSubAmt = waf("#ext_editgrid").wafGrid('getCell',rowId5,"currentReqSubAmt");
                var row6CurSubAmt = _private.addFiveNumber(row1CurSubAmt,row2CurSubAmt,row3CurSubAmt,row4CurSubAmt,row5CurSubAmt,2);
                waf("#ext_editgrid").wafGrid('setCell',rowId6,"currentReqSubAmt",row6CurSubAmt);
                //本期结算
                var row6CurSetAmt = _private.subtract(row6CurReqAmt,row6CurSubAmt,2);
                waf("#ext_editgrid").wafGrid('setCell',rowId6,"currentSetAmt",row6CurSetAmt);
                //截至本期末累计结算金额

                var row6jzsqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId6,"jzsqmljjsAmt");
                var row6jzbqAmt = _private.add(row6jzsqAmt,row6CurSetAmt,2);
                waf("#ext_editgrid").wafGrid('setCell',rowId6,"jzbqmljjsAmt",row6jzbqAmt);

                //*******************************税金*******************************
                if(isAloneTax!="1"){//多税率




                    waf("#ext_editgrid").wafGrid('setCell',rowId7,"jzsqmljjsAmt",null);
                    //本期申请金额
                    var row8CurReqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId8,"currentReqAmt");
                    var row9CurReqAmt = _private.add(row6CurReqAmt,row8CurReqAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId9,"currentReqAmt",row9CurReqAmt);
                    //本期审减金额
                    var row8CurSubAmt = waf("#ext_editgrid").wafGrid('getCell',rowId8,"currentReqSubAmt");
                    var row9CurSubAmt = _private.add(row6CurSubAmt,row8CurSubAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId9,"currentReqSubAmt",row9CurSubAmt);
                    //本期结算
                    var row9CurSetAmt = _private.subtract(row9CurReqAmt,row9CurSubAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId9,"currentSetAmt",row9CurSetAmt);
                    //截至本期末累计结算金额
                    var row9jzsqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId9,"jzsqmljjsAmt");
                    var row9jzbqAmt = _private.add(row9jzsqAmt,row9CurSetAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId9,"jzbqmljjsAmt",row9jzbqAmt);

                    //含税结算金额（表头）
                    waf("#workLoadOriAmt").wafNumberField("setValue",row9CurSetAmt);
                    //waf("#originalAmount").wafNumberField("setValue",row9CurSetAmt);



                }else{//单税率
                    var raxPct = waf("#ext_editgrid").wafGrid('getCell',rowId7,"jzsqmljjsAmt");
                    //本期申请金额
                    var row8CurReqAmt = _private.multiply(raxPct,row6CurReqAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId8,"currentReqAmt",row8CurReqAmt);
                    //本期审减金额
                    var row8CurSubAmt = _private.multiply(raxPct,row6CurSubAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId8,"currentReqSubAmt",row8CurSubAmt);
                    //本期结算
                    var row8CurSetAmt = _private.subtract(row8CurReqAmt,row8CurSubAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId8,"currentSetAmt",row8CurSetAmt);
                    //截至本期末累计结算金额
                    var row8jzsqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId8,"jzsqmljjsAmt");
                    var row8jzbqAmt = _private.add(row8jzsqAmt,row8CurSetAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId8,"jzbqmljjsAmt",row8jzbqAmt);
                    //*******************************含税结算金额合计*******************************
                    //本期申请金额
                    var row9CurReqAmt = _private.add(row6CurReqAmt,row8CurReqAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId9,"currentReqAmt",row9CurReqAmt);
                    //本期审减金额
                    var row9CurSubAmt = _private.add(row6CurSubAmt,row8CurSubAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId9,"currentReqSubAmt",row9CurSubAmt);
                    //本期结算
                    var row9CurSetAmt = _private.subtract(row9CurReqAmt,row9CurSubAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId9,"currentSetAmt",row9CurSetAmt);
                    //截至本期末累计结算金额
                    var row9jzsqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId9,"jzsqmljjsAmt");
                    var row9jzbqAmt = _private.add(row9jzsqAmt,row9CurSetAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId9,"jzbqmljjsAmt",row9jzbqAmt);

                    //含税结算金额（表头）
                    waf("#workLoadOriAmt").wafNumberField("setValue",row9CurSetAmt);
                    //waf("#originalAmount").wafNumberField("setValue",row9CurSetAmt);
                }


            }else{//非工程项
                var rowId1 = waf("#ext_editgrid").wafGrid("getRowId",1);
                var rowId2 = waf("#ext_editgrid").wafGrid("getRowId",2);
                var rowId3 = waf("#ext_editgrid").wafGrid("getRowId",3);
                var rowId4 = waf("#ext_editgrid").wafGrid("getRowId",4);
                var rowId5 = waf("#ext_editgrid").wafGrid("getRowId",5);
                var rowId6 = waf("#ext_editgrid").wafGrid("getRowId",6);

                //*******************************合计不含税*******************************
                //本期申请金额
                var row1CurReqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId1,"currentReqAmt");
                var row2CurReqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId2,"currentReqAmt");
                var row3CurReqAmt = _private.add(row1CurReqAmt,row2CurReqAmt,2);
                waf("#ext_editgrid").wafGrid('setCell',rowId3,"currentReqAmt",row3CurReqAmt);
                //本期审减金额
                var row1CurSubAmt = waf("#ext_editgrid").wafGrid('getCell',rowId1,"currentReqSubAmt");
                var row2CurSubAmt = waf("#ext_editgrid").wafGrid('getCell',rowId2,"currentReqSubAmt");
                var row3CurSubAmt = _private.add(row1CurSubAmt,row2CurSubAmt,2);
                waf("#ext_editgrid").wafGrid('setCell',rowId3,"currentReqSubAmt",row3CurSubAmt);
                //本期结算
                var row3CurSetAmt = _private.subtract(row3CurReqAmt,row3CurSubAmt,2);
                waf("#ext_editgrid").wafGrid('setCell',rowId3,"currentSetAmt",row3CurSetAmt);
                //截至本期末累计结算金额
                var row3jzsqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId3,"jzsqmljjsAmt");
                var row3jzbqAmt = _private.add(row3jzsqAmt,row3CurSetAmt,2);
                waf("#ext_editgrid").wafGrid('setCell',rowId3,"jzbqmljjsAmt",row3jzbqAmt);


                //*******************************税金*******************************
                if(isAloneTax!="1"){//多税率
                    waf("#ext_editgrid").wafGrid('setCell',rowId5,"jzsqmljjsAmt",null);
                    //本期申请金额
                    var row5CurReqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId5,"currentReqAmt");
                    var row6CurReqAmt = _private.add(row3CurReqAmt,row5CurReqAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId6,"currentReqAmt",row6CurReqAmt);
                    //本期审减金额
                    var row5CurSubAmt = waf("#ext_editgrid").wafGrid('getCell',rowId5,"currentReqSubAmt");
                    var row6CurSubAmt = _private.add(row3CurSubAmt,row5CurSubAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId6,"currentReqSubAmt",row6CurSubAmt);
                    //本期结算
                    var row6CurSetAmt = _private.subtract(row6CurReqAmt,row6CurSubAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId6,"currentSetAmt",row6CurSetAmt);
                    //截至本期末累计结算金额
                    var row6jzsqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId6,"jzsqmljjsAmt");
                    var row6jzbqAmt = _private.add(row6jzsqAmt,row6CurSetAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId6,"jzbqmljjsAmt",row6jzbqAmt);
                    //含税结算金额（表头）
                    waf("#workLoadOriAmt").wafNumberField("setValue",row6CurSetAmt);
                    //waf("#originalAmount").wafNumberField("setValue",row6CurSetAmt);

                }else{//单税率
                    var raxPct = waf("#ext_editgrid").wafGrid('getCell',rowId4,"jzsqmljjsAmt");
                    //本期申请金额
                    var row5CurReqAmt = _private.multiply(raxPct,row3CurReqAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId5,"currentReqAmt",row5CurReqAmt);
                    //本期审减金额
                    var row5CurSubAmt = _private.multiply(raxPct,row3CurSubAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId5,"currentReqSubAmt",row5CurSubAmt);
                    //本期结算
                    var row5CurSetAmt = _private.subtract(row5CurReqAmt,row5CurSubAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId5,"currentSetAmt",row5CurSetAmt);
                    //截至本期末累计结算金额
                    var row5jzsqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId5,"jzsqmljjsAmt");
                    var row5jzbqAmt = _private.add(row5jzsqAmt,row5CurSetAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId5,"jzbqmljjsAmt",row5jzbqAmt);

                    //*******************************含税结算金额合计*******************************
                    //本期申请金额
                    var row6CurReqAmt = _private.add(row3CurReqAmt,row5CurReqAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId6,"currentReqAmt",row6CurReqAmt);
                    //本期审减金额
                    var row6CurSubAmt = _private.add(row3CurSubAmt,row5CurSubAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId6,"currentReqSubAmt",row6CurSubAmt);
                    //本期结算
                    var row6CurSetAmt = _private.subtract(row6CurReqAmt,row6CurSubAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId6,"currentSetAmt",row6CurSetAmt);
                    //截至本期末累计结算金额
                    var row6jzsqAmt = waf("#ext_editgrid").wafGrid('getCell',rowId6,"jzsqmljjsAmt");
                    var row6jzbqAmt = _private.add(row6jzsqAmt,row6CurSetAmt,2);
                    waf("#ext_editgrid").wafGrid('setCell',rowId6,"jzbqmljjsAmt",row6jzbqAmt);

                    //含税结算金额（表头）
                    waf("#workLoadOriAmt").wafNumberField("setValue",row6CurSetAmt);
                    //waf("#originalAmount").wafNumberField("setValue",row6CurSetAmt);
                }
            }
        },


        subtract:function(obj1,obj2,scale){
            //为方便，强制设为3
            var value1 = _private.isEmpty(obj1)?0:Number(obj1);
            var value2 = _private.isEmpty(obj2)?0:Number(obj2);
            var value = value1 - value2;
            if(scale){
                value = _private.fixNumber(value,scale);

            }
            return value;
        },
        multiply:function(obj1,obj2,scale){
            //为方便，强制设为3
            var value1 = _private.isEmpty(obj1)?0:Number(obj1);
            var value2 = _private.isEmpty(obj2)?0:Number(obj2);
            var value = value1 * value2;
            if(scale){
                value = _private.fixNumber(value,scale);

            }
            return value;
        },
        add:function(obj1,obj2,scale){
            //为方便，强制设为3
            var value1 = _private.isEmpty(obj1)?0:Number(obj1);
            var value2 = _private.isEmpty(obj2)?0:Number(obj2);
            var value = value1 + value2;
            if(scale){
                value = _private.fixNumber(value,scale);

            }
            return value;
        },
        addFiveNumber:function(obj1,obj2,obj3,obj4,obj5,scale){
            //为方便，强制设为3
            var value1 = _private.isEmpty(obj1)?0:Number(obj1);
            var value2 = _private.isEmpty(obj2)?0:Number(obj2);
            var value3 = _private.isEmpty(obj3)?0:Number(obj3);
            var value4 = _private.isEmpty(obj4)?0:Number(obj4);
            var value5 = _private.isEmpty(obj5)?0:Number(obj5);
            var value = value1 + value2 +value3+value4+value5;
            if(scale){
                value = _private.fixNumber(value,scale);

            }
            return value;
        },

        isEmpty:function(name){
            return (name==null || $.trim(name)=="");
        },

        fixNumber:function(value,scale){
            var tmp = "1";
            for(var i=1;i<=scale;i++){
                tmp = tmp+"0";
            }
            tmp = Number(tmp);
            var result = Math.round(value*tmp)/tmp;
            var newResult = result+"";
            if(newResult.indexOf(".")>=0){
                return result;
            }else{
                return Number(result).toFixed(scale);
            }
        }

        ,
        extSaveOverWrite:function(e){
            _self.fireEvent('saveActionEvent');
        },

        // submitBefore:function(e){
        //     if(!_private.verifyInput()){
        //         return false;
        //     }
        //     ReWorkLoadConfirmBillEditPage.beforeSubmit(e);
        // }
        // ,
        extSaveBefore:function(e){
            if(!_private.verifyInput()){
                return false;
            }
            ReWorkLoadConfirmBillEditPage.saveBefore(e);
        },



        verifyInput:function(){
            var contractValue = waf("#contract").wafPromptBox("getValue");
            if(contractValue){
                var returnData = _private.doControllerMethod("/fdc/finance/web/ReWorkLoadConfirmBill.do?method=checkIsAllAudit",{contractId:contractValue.id,id:_self._model.id});
                if(returnData == 1 || returnData == "1"){
                    _self.showInfo("该合同存在未审批完成的产值确认单，此单据不允许保存！");
                    return false;
                }
            }else{
                _self.showInfo("合同信息有误，请重新选择！");
                return false;
            }

            var curConFinishStartDate = waf("#ext_curConFinishStartDate").wafDatePicker("getValue");
            var curConFinishEndDate = waf("#ext_curConFinishEndDate").wafDatePicker("getValue");
            if(!curConFinishStartDate || curConFinishStartDate.length==0 || !curConFinishEndDate || curConFinishEndDate.length==0){
                _self.showInfo("本次合同结算开始日期和本次合同结算截止日期不能为空！");
                return false;
            }else{
                //结束日期 - 开始日期
                var subtractTime = _private.subtract(curConFinishEndDate.getTime(),curConFinishStartDate.getTime(),0);
                if(subtractTime<0){
                    _self.showInfo("本次合同结算开始日期不能大于本次合同结算截止日期！");
                    return false;
                }
            }

            return true;
        },


        mergeTableByIndex:function(tableId,top,left,bottom,right){
            //第一列是id列
            left = left+1;
            right = right+1;
            var rowspan = bottom-top+1;
            var colspan = right-left+1;
            var colName = waf("#"+tableId).wafGrid("getColumnName",left);
            var rowId = waf("#"+tableId).wafGrid("getRowId",top);
            var cell = waf("#"+tableId).wafGrid("getCellObject",rowId,colName);
            if(rowspan>1){
                waf(cell).attr('rowspan', rowspan);
            }
            if(colspan>1){
                waf(cell).attr('colspan', colspan);
            }
            //隐藏融合单元格
            for(var i=top;i<=bottom;i++){
                for(var j=left;j<=right;j++){
                    if(i==top && j==left){
                        continue;
                    }
                    var nextId = waf("#"+tableId).wafGrid("getRowId",i);
                    var nextColName = waf("#"+tableId).wafGrid("getColumnName",j);
                    var nexCell = waf("#"+tableId).wafGrid("getCellObject",nextId,nextColName);
                    nexCell.hide();
                }
            }

        },
        //反向融合行                                 7,    4,   7,     8
        contraryMergeTableByIndex:function(tableId,top,left,bottom,right){
            //第一列是id列
            left = left+1;
            right = right+1;
            var rowspan = bottom-top+1;
            var colspan = right-left+1;
            // var colName = waf("#"+tableId).wafGrid("getColumnName",left);
            var rowId = waf("#"+tableId).wafGrid("getRowId",top);
            var cell = waf("#"+tableId).wafGrid("getCellObject",rowId,"remark");
            if(rowspan>1){
                waf(cell).attr('rowspan', 1);
            }
            if(colspan>1){
                waf(cell).attr('colspan', 6);
            }
            //隐藏融合单元格
            for(var i=top;i<=bottom;i++){
                for(var j=left-1;j<=right;j++){
                    if(i==top && j==left-1){
                        continue;
                    }
                    var nextId = waf("#"+tableId).wafGrid("getRowId",i);
                    var nextColName = waf("#"+tableId).wafGrid("getColumnName",j);
                    var nexCell = waf("#"+tableId).wafGrid("getCellObject",nextId,nextColName);
                    nexCell.hide();
                }
            }
        },

        beforeSave:function(e){
            if(!_private.verifyInput()){
                return false;
            }
            ReWorkLoadConfirmBillEditPage.saveBefore(e);
        },



        submitBeforeBizCheckNew:function(e){
            if(!_private.verifyInput()){
                return false;
            }
        }
        ,
        editGridBeforeEdit:function(rowid,cellname,value,iRow,iCol,rowdata){
        }
    });//@endPrivate
    /**************************开发区域结束**********************************************/
    return _public;
});
